			<?php
            /*
                *  Code To Paypal Button Start
            */
            ini_set("track_errors", true);
            //set PayPal Endpoint to sandbox
            $url = trim("https://svcs.sandbox.paypal.com/AdaptivePayments/Pay");
            $API_UserName = "fernan_1308771699_biz_api1.gmail.com";
            $API_Password = "1308771707";
            $API_Signature = "A.y6-5L0MBLxPrgTR9z.v2XX5v9fAHqzh1k-tujBzHsZxCXJd67m5Qu-";
            //Default App ID for Sandbox	
            $API_AppID = "APP-80W284485P519543T";
            
            $API_RequestFormat = "NV";
            $API_ResponseFormat = "NV";
            //Create request payload with minimum required parameters
            $bodyparams = $bodyparams; 
            // convert payload array into url encoded query string
            $body_data = http_build_query($bodyparams, "", chr(38));
            try
            {
            //create request and add headers
            $params = array("http" => array( 
            "method" => "POST",
            "content" => $body_data,
            "header" =>  "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" .
            "X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" .
            "X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" .
            "X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" .
            "X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" .
            "X-PAYPAL-RESPONSE-DATA-FORMAT: " . $API_ResponseFormat . "\r\n" 
            ));
            //create stream context
            $ctx = stream_context_create($params);
            //open the stream and send request
            $fp = @fopen($url, "r", false, $ctx);
            //get response
            $response = stream_get_contents($fp);
            //check to see if stream is open
            if ($response === false) {
            throw new Exception("php error message = " . "$php_errormsg");
            }
            //close the stream
            fclose($fp);
            //parse the ap key from the response
            $keyArray = explode("&", $response);
            foreach ($keyArray as $rVal){
            list($qKey, $qVal) = explode ("=", $rVal);
            $kArray[$qKey] = $qVal;
            echo "<pre>";
            print_r($kArray);
            echo "</pre>";
            exit;
            }
            //set url to approve the transaction
            //$payPalURL = "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" . $kArray["payKey"];
            //print the url to screen for testing purposes
            if ( $kArray["responseEnvelope.ack"] == "Success") {
            
            $PayKey = $kArray["payKey"];
            $payPalURL = "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" . $kArray["payKey"];
            ?>
            <div class="pad15" style=" width:100%;">
              <?php
                         echo   '<a href="' . $payPalURL . '" class="sea_btn">PayPal</a>';
                ?>
              <!--<script type="text/javascript" src="https://www.paypalobjects.com/js/external/dg.js"></script>
                <form  action="https://sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=<?php //echo $PayKey; ?>" target="PPDGFrame"> 
                <input id="type" type="hidden" name="expType" value="light"> 
                <input id="paykey" type="hidden" name="paykey" value="<?php //echo $PayKey; ?>"> 
                <input id="preapprovalkey" type="hidden" name="preapprovalkey" value="PA-16L22977CT284011E"> 
                <input type="submit" id="submitBtn" value="PayPal"> 
                <script>
                var dg = new PAYPAL.apps.DGFlow({
                // the HTML ID of the form button
                trigger: 'submitBtn'
                });
                </script>
                </form>
                --> 
            </div>
            <?php
            }
            else {
            $this->Set('PayKeyError', 'Reload Page');
            }
            }
            catch(Exception $e) {
            $this->Set('PayKeyError', $e->getMessage());
            }
            /*
                *  Code To Paypal End
            */
            
            ?>
